﻿using System;
using System.Collections.Generic;
using System.Text;
using YouHP.Utility;
using YouHP.BLL;
using System.Web;
using YouHP.Model;

namespace YouHP.Pages.Ajax
{
    public class LogReplyDeleteAjax:YouHP.Pages.BasePage
    {

        protected UserInfo ProfileUserData;
        protected List<LogReplyInfo> LogReplyDataList;
        protected int PageIndex;
        protected int DataCount;
        protected int PageCount;
        protected string PagingString;


        protected override void ShowPage()
        {
            base.ShowPage();
            if (ErrorCount > 0) return;

            //判断条件
            int lid = RequestTools.GetInt("lid", 0);
            int rid = RequestTools.GetInt("rid", 0);
            if (lid <= 0) return;
            if (rid <= 0) return;

            LogTopicInfo Logdata = LogTopicBLL.Instance.GetLogTopicInfo(lid);
            if (Logdata.Id <= 0) return;


            //执行删除
            LogReplyBLL.Instance.DeleteLogReply(lid, rid);

            //生成返回XML

            PageIndex = RequestTools.GetQueryInt("page", 1);

            LogReplyDataList = LogReplyBLL.Instance.GetLogReplyList(10, PageIndex, Logdata.Id, out DataCount);

            PageCount = Utils.GetPageCount(DataCount, 10);

            StringBuilder sb = new StringBuilder();
            sb.Append("<div class=\"pl_title\">" + "<span style=\"float:left;\">对该日志的评论</span>" + "<span style=\"float:right;\">" + "共<b><font name=\"fedcount\" id=\"fedcount\">" + DataCount + "</font></b>条</span></div>");
            sb.Append("<ul class=\"hugbook\" id=\"hugbook\">");

            foreach (LogReplyInfo item in LogReplyDataList)
            {

                sb.Append("<li><div style=\"padding-left:20px; text-align:center; float:left;\">");
                string TempUrl = "/Profile/Index.aspx?uid=" + item.PostUserId;
                sb.Append("<a href=\"" + this.GetUrl(TempUrl) + "\"><img class=\"avatar\" width=\"45\" height=\"45\" src=\"" + UserBLL.Instance.GetUserInfo(item.PostUserId).Avatar + "\"/>");
                sb.Append("</a></div>");
                sb.Append("<div style=\"margin:0pt 10px 0pt 82px;\"><p class=\"graytext\"><span style=\"float:right;\">");
                if (UserData.Id > 0)
                {
                    if (UserData.Id != item.PostUserId)
                    {
                      
                        sb.Append("<a href=\"javascript:replyLogReply(\'" + item.PostUserName + "\');\">回复</a>&nbsp;&nbsp;&nbsp;&nbsp;");
                    }
                    //if (item.PostUserId == UserData.Id)
                    //{
                    //    TempUrl = "/Profile/LogReplyEdit.aspx?id=" + item.Id;
                    //    sb.Append("<a href=\"" + this.GetUrl(TempUrl) + "\">编辑</a>&nbsp;&nbsp;&nbsp;&nbsp;");
                    //}
                    if (item.PostUserId == UserData.Id || Logdata.HostUserId == UserData.Id)
                    {

                        sb.Append("<a href=\"javascript:if(window.confirm(\'确定删除该评论？\')) LogReplyDelete(" + item.Id + ");\">删除</a>&nbsp;&nbsp;&nbsp;&nbsp;");
                    }
                }
                TempUrl = "/Profile/Index.aspx?uid=" + item.PostUserId;
                sb.Append("</span><a class=\"client_name\" href=\"" + this.GetUrl(TempUrl) + "\">" + item.PostUserName + "</a>");
                TempUrl = item.PostTime.ToString("yyyy-MM-dd  hh:mm");
                sb.Append("&nbsp;" + TempUrl + "</p><p class=\"longtextfix\">" + item.Body + "</p></div>");
                sb.Append("<div style=\"clear: both;\"/></li>");
            }
            sb.Append("</ul>");

            PagingString = this.GetPagingString2(PageIndex, PageCount, "", "javascript:ViewLogReplyPage");
            sb.Append("<div class=\"pages\" style=\"padding:10px 5px;\">" + PagingString + "</div>");


            ResponseXML(sb);




        }

        private void ResponseXML(StringBuilder sb)
        {
            System.Web.HttpContext.Current.Response.Clear();
            System.Web.HttpContext.Current.Response.ContentType = "Text/html";
            System.Web.HttpContext.Current.Response.Expires = 0;

            System.Web.HttpContext.Current.Response.Write(sb.ToString());
            System.Web.HttpContext.Current.Response.End();
        }
    }
}

